<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/*
 * post请求
 * */

function curl_post_request($url,$data){
    $curl=curl_init();
    curl_setopt($curl,CURLOPT_AUTOREFERER,true);
    curl_setopt($curl,CURLOPT_HEADER,false);
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
    $res=curl_exec($curl);
    if($res){
        return json_decode($res,true);
    }else{
        $info=curl_getinfo($curl);
        file_put_contents(__PUBLIC__."/log/im/sendSms.log",json_encode($info));
        return false;
    }
    curl_close($curl);
}

/*
 * get请求
 * */
function curl_get_request($url){
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_AUTOREFERER,true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl,CURLOPT_URL,$url);

    $res=curl_exec($curl);
    if($res){
        return json_decode($res,true);
    }else{
        $info=curl_getinfo($curl);
        file_put_contents(__PUBLIC__."log/im/sendSms.log",json_encode($info));
        return false;
    }
    curl_close($curl);
}


